package com.lmx.repoDomain.tmodel;

import io.katharsis.resource.annotations.JsonApiIncludeByDefault;
import io.katharsis.resource.annotations.JsonApiLookupIncludeAutomatically;
import io.katharsis.resource.annotations.JsonApiResource;
import io.katharsis.resource.annotations.JsonApiToOne;

import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;

import com.google.common.collect.Sets;
import com.lmx.repoDomain.tmodel.business.User;

/**
 * 评价
 *
 * @author ytche
 * @date 2017年7月21日
 *
 */
@JsonApiResource(type = "appraise")
@Entity
@Table(name = "tnb_appraise")
public class Appraise extends BaseEntity {

	private static final long serialVersionUID = 1L;
	private String name;

	private User createUser;
	private Integer completeStatus;
	private Integer endTime;
	private Set<AppraiseItem> items = Sets.newLinkedHashSet();
	private Set<AppraiseResult> results;
	private String remark;
	private Integer incluedEmplooye;// 是否进行员工评价,0否1是

	private Integer publishStatus;
	private Integer publichNum;

	@Column(name = "name")
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@JsonApiToOne
	@JsonApiIncludeByDefault
	@ManyToOne(fetch = FetchType.EAGER, cascade = CascadeType.REFRESH)
	@Fetch(FetchMode.JOIN)
	@JoinColumn(name = "create_user_id")
	public User getCreateUser() {
		return createUser;
	}

	public void setCreateUser(User createUser) {
		this.createUser = createUser;
	}

	@Column(name = "complete_status")
	public Integer getCompleteStatus() {
		return completeStatus;
	}

	public void setCompleteStatus(Integer completeStatus) {
		this.completeStatus = completeStatus;
	}

	@Column(name = "end_time")
	public Integer getEndTime() {
		return endTime;
	}

	public void setEndTime(Integer endTime) {
		this.endTime = endTime;
	}

	@JsonApiToOne
	@JsonApiIncludeByDefault
	@ManyToMany(fetch = FetchType.EAGER, cascade = CascadeType.REFRESH)
	@JoinTable(name = "rel_appraise_item", joinColumns = { @JoinColumn(name = "appraise_id") }, inverseJoinColumns = { @JoinColumn(name = "item_id") })
	public Set<AppraiseItem> getItems() {
		return items;
	}

	public void setItems(Set<AppraiseItem> items) {
		this.items = items;
	}

	@Column(name = "remark")
	public String getRemark() {
		return remark;
	}

	public void setRemark(String remark) {
		this.remark = remark;
	}

	@Column(name = "publish_status")
	public Integer getPublishStatus() {
		return publishStatus;
	}

	public void setPublishStatus(Integer publishStatus) {
		this.publishStatus = publishStatus;
	}

	@Column(name = "publish_num")
	public Integer getPublichNum() {
		return publichNum;
	}

	public void setPublichNum(Integer publichNum) {
		this.publichNum = publichNum;
	}

	@Column(name = "include_employee")
	public Integer getIncluedEmplooye() {
		return incluedEmplooye;
	}

	public void setIncluedEmplooye(Integer incluedEmplooye) {
		this.incluedEmplooye = incluedEmplooye;
	}

	@OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.REFRESH, mappedBy = "appraise")
	@Fetch(FetchMode.JOIN)
	@JsonApiToOne
	@JsonApiLookupIncludeAutomatically
	public Set<AppraiseResult> getResults() {
		return results;
	}

	public void setResults(Set<AppraiseResult> results) {
		this.results = results;
	}

}
